//
//  VideoCollectionCell.m
//  VideoPic
//
//  Created by GH on 16/3/21.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "VideoCollectionCell.h"
#import "VideoTableViewCell.h"
#import "NetworkingHandle.h"
#import "ModelForVideo.h"

@interface VideoCollectionCell ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic ,retain)UITableView *tableview;
@property (nonatomic ,retain)NSString *min_time;
@property (nonatomic ,retain)NSMutableArray *arrayData;



@end

@implementation VideoCollectionCell


- (instancetype)initWithFrame:(CGRect)frame {

    self = [super initWithFrame:frame];
    if (self) {
        
        [self data];
        [self createTableview];
    }

    return self;
}





- (void)data {
    if (self.arrayData == nil) {
        self.arrayData = [NSMutableArray array];
    }
    
    [NetworkingHandle handleWorkData:@"http://ic.snssdk.com/neihan/stream/mix/v1/?content_type=-104&iid=3920941040&os_version=9.2.1&os_api=18&app_name=joke_essay&channel=App%20Store&device_platform=ipad&idfa=9A005A60-CDB5-48F2-B08D-064B7D6249F1&vid=AB901E28-9054-4CFB-A004-D778A2CF3AD7&openudid=fbfa64cd1ba39d415dc3cec95d4a05f39d5d1c6d&device_type=iPad%20Mini%20Retina&version_code=5.0.1&ac=WIFI&screen_width=1536&device_id=12766798812&aid=7&city=%E8%BE%BD%E5%AE%81%E7%9C%81&content_type=-104&count=30&essence=1&latitude=38.88252117791897&longitude=121.5398445403335&message_cursor=0&min_time=1458617484&mpic=1" AndBody:nil value:nil handleBlock:^(id result) {
        
        NSDictionary *dicData = [result objectForKey:@"data"];
        self.min_time = [dicData objectForKey:@"min_time"];
        NSArray *arrCon = [dicData objectForKey:@"data"];
        for (NSDictionary *dicCon in arrCon) {
            NSDictionary *dicGroup = [dicCon objectForKey:@"group"];
            ModelForVideo *model = [[ModelForVideo alloc] init];
            [model setValuesForKeysWithDictionary:dicGroup];
            [self.arrayData addObject:model];
            
            NSDictionary *dicUser = [dicGroup objectForKey:@"user"];
            model.name = [dicUser objectForKey:@"name"];
            model.avatar_url = [dicUser objectForKey:@"avatar_url"];
        }
        
        [self.tableview reloadData];
    }];
}






- (void)createTableview {

    self.tableview = [[UITableView alloc] initWithFrame:self.contentView.bounds style:UITableViewStylePlain];
    [self.contentView addSubview:self.tableview];
    self.tableview.dataSource = self;
    self.tableview.delegate = self;

    [self.tableview registerClass:[VideoTableViewCell class] forCellReuseIdentifier:@"pool"];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return self.arrayData.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    VideoTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"pool"];

    ModelForVideo *model = [self.arrayData objectAtIndex:indexPath.row];
    [cell passWithModel:model];
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

    return 300;
}



@end
